<?php
/**
 * RedCross Application
 *
 * @copyright Copyright (c) 2010, Kristian Stokke Tryggestad, Rune Vikestad, Andreas Flaten Wist, Simen Nicolai Echholt, Ole Henrik Jahren
 */


class Admin_Form_Group_AddUser extends RedCross_Form
{

    public function init()
    {
		$this->addElement('select', 'name', array(
			'required'	=> true,
			'label'		=> 'Navn',
		));

        $this->getElement('name')->addMultiOption(null, '-- Velg bruker --');

        $this->addElement('submit', 'add_user', array(
            'required' => true,
            'ignore'   => true,
            'label'    => 'Legg til medlem',
        ));

    }

    public function fillForm($groupId)
    {
        $service = RedCross_Factory::getService('Core_Service_Group');
        $users = $service->fetchUsersNotInGroup($groupId);
        $array = array();
        foreach ($users as $user) {
        	$array[$user['id']] = $user['Member']['first_name'] . ' ' . $user['Member']['last_name'] . ' (' . $user['username'] . ')';
        }

        if (!empty($array)) {
        	$this->getElement('name')->addMultiOptions($array);
        }
    }
}
